package com.dst.controller;

import com.dst.entity.Book;
import com.dst.entity.Category;
import com.dst.service.BookService;
import com.dst.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    @Qualifier("bookService")
    private BookService bookService;
    @Autowired
    @Qualifier("categoryService")
    private CategoryService categoryService;
    @RequestMapping("/showMain")
    public String selectRecommend(Model model){
        List<Book> recommend = bookService.selectRecommend();
        model.addAttribute("recommend",recommend);
        List<Book> hotSale = bookService.selectHotSale();
        model.addAttribute("hotSale",hotSale);
        List<Book> justin = bookService.selectJustIn();
        model.addAttribute("justin",justin);
        List<Book> newBookSale = bookService.selectNewBookSale();
        model.addAttribute("newBookSale",newBookSale);
        List<Category> granding = categoryService.selectGranding();
        model.addAttribute("granding",granding);
        return "forward:/main/main.jsp";
    }
    @RequestMapping("selectInformation")
    public String selectInformation(String name,Model model){
        Book book = bookService.selectByName(name);
        model.addAttribute("information",book);
        return "forward:/main/product.jsp";
    }
}
